//package com.wiloon.java8x.datadictionary;
//
//import com.wiloon.java8x.datadictionary.excel.DataDictionaryBuilder;
//import com.wiloon.java8x.datadictionary.excel.DataDictionaryBuilderImpl;
//import com.wiloon.java8x.datadictionary.excel.DataDictionaryDesigner;
//import com.wiloon.java8x.datadictionary.excel.DataDictionaryDesignerImpl;
//import com.wiloon.java8x.datetime.DateTimeTest;
//import org.apache.poi.ss.usermodel.*;
//import org.apache.poi.ss.util.CellRangeAddress;
//import org.apache.poi.xssf.usermodel.*;
//import org.slf4j.Logger;
//import org.slf4j.LoggerFactory;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.stereotype.Service;
//
//import java.util.List;
//
///**
// * Created by Administrator on 2015/5/21.
// */
//
//@Service
//public class DataDictionaryHelperImpl implements DataDictionaryHelper {
//    private static Logger logger = LoggerFactory
//            .getLogger(DictionaryDaoImpl.class);
//    @Autowired
//    DictionaryService dictionaryService;
//
//    public void createDataDictionary(DataDictionary dataDictionary) {
//        XSSFWorkbook workbook = new XSSFWorkbook();
//        DataDictionaryBuilder cellBuilder = new DataDictionaryBuilderImpl();
//        cellBuilder.setWorkbook(workbook);
//        DataDictionaryDesigner dataDictionaryCellDesigner = new DataDictionaryDesignerImpl(cellBuilder);
//
//        try {
//            //read all tables;
//            List<DatabaseTable> tables = dictionaryService.readAllTables();
//            XSSFSheet sheet0 = dataDictionaryCellDesigner.createNewSheet("Table List");
//            dataDictionaryCellDesigner.createCellColorBold(0, 0, "No");
//            dataDictionaryCellDesigner.createCellColorBold(0,1,"Table Name");
//
//            for(int rowIndex=0;rowIndex<tables.size();rowIndex++){
//                dataDictionaryCellDesigner.createCell(rowIndex+1,0,""+(rowIndex+1));
//                dataDictionaryCellDesigner.createCell(rowIndex+1,1,tables.get(rowIndex).getTableName());
//            }
//
//            dataDictionaryCellDesigner.setBorder( 0, 0, 2, 63);
//
//            //tables.size();
//
//            for (int tableIndex = 0; tableIndex < tables.size(); tableIndex++) {
//               //for (int tableIndex = 43; tableIndex < 44; tableIndex++) {
//                logger.debug("table index=" + tableIndex);
//                DatabaseTable table = tables.get(tableIndex);
//
//                XSSFSheet sheet = dataDictionaryCellDesigner.createNewSheet();
//                dataDictionaryCellDesigner.setSheetName(table.getTableName());
//
//                table = dictionaryService.readColumnsByTable(table);
//
//                dataDictionaryCellDesigner.createColorCell(0, 0, "DB Design");
//                dataDictionaryCellDesigner.createCellBold(0, 2, "Application:");
//                dataDictionaryCellDesigner.createCell(0, 4, dataDictionary.getProjectName());
//                dataDictionaryCellDesigner.createColorCell(0, 10, "Creater:");
//                dataDictionaryCellDesigner.createCell(0, 11, dataDictionary.getCreater());
//                dataDictionaryCellDesigner.createColorCell(1, 10, "Date:");
//                dataDictionaryCellDesigner.createCell(1, 11, DateTimeTest.getCurrentDateYYYYMMDD());
//                dataDictionaryCellDesigner.createCellBold(2, 2, "Table:");
//                dataDictionaryCellDesigner.createCell(2, 4, table.getTableName());
//                dataDictionaryCellDesigner.createColorCell(2, 10, "Modifier:");
//                dataDictionaryCellDesigner.createColorCell(3, 10, "Date:");
//
//                sheet.addMergedRegion(new CellRangeAddress(0, 3, 0, 1));
//                sheet.addMergedRegion(new CellRangeAddress(0, 1, 2, 3));
//                sheet.addMergedRegion(new CellRangeAddress(2, 3, 2, 3));
//
//                sheet.addMergedRegion(new CellRangeAddress(0, 1, 4, 9));
//                sheet.addMergedRegion(new CellRangeAddress(2, 3, 4, 9));
//
//                //columnIndex title
//                dataDictionaryCellDesigner.createColorCell(2, 10, "Modifier:");
//                dataDictionaryCellDesigner.createColorCell(5, 0, "No");
//                dataDictionaryCellDesigner.createColorCell(5, 1, "FIELD NAME");
//                dataDictionaryCellDesigner.createColorCell(5, 4, "DATA TYPE");
//                dataDictionaryCellDesigner.createColorCell(5, 5, "DATA LENGTH");
//                dataDictionaryCellDesigner.createColorCell(5, 6, "NULLABLE");
//                dataDictionaryCellDesigner.createColorCell(5, 7, "KEY");
//                dataDictionaryCellDesigner.createColorCell(5, 8, "DEFAULT");
//                dataDictionaryCellDesigner.createColorCell(5, 9, "COMMENTS");
//                sheet.addMergedRegion(new CellRangeAddress(5, 5, 1, 3));
//                sheet.addMergedRegion(new CellRangeAddress(5, 5, 9, 11));
//
//                int columnInfoIndex = 6;
//
//                for (int j = 0; j < table.getColumns().size(); j++) {
//                    int row = columnInfoIndex + j;
//                    dataDictionaryCellDesigner.createCell(row, 0, "" + j);
//                    dataDictionaryCellDesigner.createCell(row, 1, table.getColumns().get(j).getColumnName());
//                    dataDictionaryCellDesigner.createCell(row, 4, table.getColumns().get(j).getDataType());
//                    dataDictionaryCellDesigner.createCell(row, 5, table.getColumns().get(j).getDataLength());
//                    dataDictionaryCellDesigner.createCell(row, 6, table.getColumns().get(j).getNullable());
//                    dataDictionaryCellDesigner.createCell(row, 7, table.getColumns().get(j).getKey());
//                    dataDictionaryCellDesigner.createCell(row, 8, table.getColumns().get(j).getDefaultValue());
//                    dataDictionaryCellDesigner.createCell(row, 9, table.getColumns().get(j).getComments());
//                    sheet.addMergedRegion(new CellRangeAddress(row, row, 1, 3));
//                    sheet.addMergedRegion(new CellRangeAddress(row, row, 9, 11));
//                }
//
//                dataDictionaryCellDesigner.setBorder( 0, 0, 12, 4);
//                dataDictionaryCellDesigner.setBorder(0, 5, 12, 5 + table.getColumns().size() + 1);
//            }
//
//            dataDictionaryCellDesigner.generateFile();
//
//        } catch (Exception e) {
//            e.printStackTrace();
//        }
//
//    }
//}
